package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "TestController 测试接口")
// 表示返回的结果是数据
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation(value = "测试接口1，打印Spring boot")
    @GetMapping("/hello")
    public String hello() {
//        System.out.println("111");
        return "hello,Spring boot...";
    }

    @ApiOperation(value = "测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam(value = "姓名") @RequestParam("name") String name) {
        return AppResult.success("hello: " + name);
    }
    @ApiOperation(value = "测试接口2，这是一个Exception")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation(value = "测试接口3，这是一个ApplicationException")
    @GetMapping("/appException")
    public AppResult testAppException() {
        throw new ApplicationException("这是一个ApplicationException...");
    }
}
